import Mock from 'mockjs2'
import { builder, getQueryParameters } from '../util'



const pageData = (options) => {

  const queryParameters = getQueryParameters(options)
  if (queryParameters && !queryParameters.count) {
    queryParameters.total = 100
  }

  let page = Number(queryParameters.page) || 1
  let size = Number(queryParameters.pageSize) || 10

  const data = []
  for (let i = (page - 1) * 10; i < page * size; i++) {
    const idKey = i + 1
    data.push({
      WW_XH: idKey,
      WW_WB: `文本${idKey}`,
      WW_WBK: `文本框${idKey}`,
      WW_XLK: `下拉框${idKey}`,
      WW_SF: Mock.mock('@boolean'),
      WW_DX: `单选${idKey}`,
      WW_DXK: `多选框${idKey}`,
      WW_ZS: `整数${idKey}`,
      WW_SZ: `数字${idKey}`,
      WW_JE: `金额${idKey}`,
      WW_RQ:  new Date().getTime() + idKey * 3600 * 24 * 1000 + idKey * 3600000
    })
  }

  const json = {
    records: data,
    current: page,
    size: size,
    total: queryParameters.total
  }

  return builder(json)
}

const getData = (options) => {
  const idKey = options.url.replace(/.+\/(\d+)$/, '$1')
  const json = {
    WW_XH: idKey,
    WW_WB: `文本${idKey}`,
    WW_WBK: `文本框${idKey}`,
    WW_XLK: `下拉框${idKey}`,
    WW_SF: Mock.mock('@boolean'),
    WW_DX: `单选${idKey}`,
    WW_DXK: [`多选框${idKey}`],
    WW_ZS: `整数${idKey}`,
    WW_SZ: `数字${idKey}`,
    WW_JE: `金额${idKey}`,
    WW_RQ:  new Date().getTime() + idKey * 3600 * 24 * 1000 + idKey * 3600000
  }

  return builder(json)
}



// 地区数据
const dqData = (options) => {
  const queryParameters = getQueryParameters(options)
  const code = queryParameters.code

  let json = [
    {WW_DQMC: '北京市', WW_DQBM: 110000, children: [
      {WW_DQMC: '东城区', WW_DQBM: 110101},
      {WW_DQMC: '西城区', WW_DQBM: 110102},
      {WW_DQMC: '朝阳区', WW_DQBM: 110105},
      {WW_DQMC: '丰台区', WW_DQBM: 110106},
      {WW_DQMC: '石景山', WW_DQBM: 110107},
      {WW_DQMC: '海淀区', WW_DQBM: 110108},
      {WW_DQMC: '门头沟', WW_DQBM: 110109},
      {WW_DQMC: '房山区', WW_DQBM: 110111},
      {WW_DQMC: '通州区', WW_DQBM: 110112},
      {WW_DQMC: '顺义区', WW_DQBM: 110113},
      {WW_DQMC: '昌平区', WW_DQBM: 110114},
      {WW_DQMC: '大兴区', WW_DQBM: 110115},
      {WW_DQMC: '怀柔区', WW_DQBM: 110116},
      {WW_DQMC: '平谷区', WW_DQBM: 110117},
      {WW_DQMC: '密云区', WW_DQBM: 110118},
      {WW_DQMC: '延庆区', WW_DQBM: 110119}
    ]},
    // {WW_DQMC: '北京市', WW_DQBM: 110000},
    {WW_DQMC: '天津市', WW_DQBM: 120000},
    {WW_DQMC: '河北省', WW_DQBM: 130000},
    {WW_DQMC: '山西省', WW_DQBM: 140000},
    {WW_DQMC: '内蒙古自治区', WW_DQBM: 150000},
    
    {WW_DQMC: '辽宁省', WW_DQBM: 210000},
    {WW_DQMC: '吉林省', WW_DQBM: 220000},
    {WW_DQMC: '黑龙江省', WW_DQBM: 230000},
    
    {WW_DQMC: '上海市', WW_DQBM: 310000},
    {WW_DQMC: '江苏省', WW_DQBM: 320000},
    {WW_DQMC: '浙江省', WW_DQBM: 330000},
    {WW_DQMC: '安徽省', WW_DQBM: 340000},
    {WW_DQMC: '福建省', WW_DQBM: 350000},
    {WW_DQMC: '江西省', WW_DQBM: 360000},
    {WW_DQMC: '山东省', WW_DQBM: 370000},

    {WW_DQMC: '河南省', WW_DQBM: 410000},
    {WW_DQMC: '湖北省', WW_DQBM: 420000},
    {WW_DQMC: '湖南省', WW_DQBM: 430000},
    {WW_DQMC: '广东省', WW_DQBM: 440000},
    {WW_DQMC: '广西壮族自治区', WW_DQBM: 450000},
    {WW_DQMC: '海南省', WW_DQBM: 460000},
    
    {WW_DQMC: '重庆市', WW_DQBM: 500000},
    {WW_DQMC: '四川省', WW_DQBM: 510000},
    {WW_DQMC: '贵州省', WW_DQBM: 520000},
    {WW_DQMC: '云南省', WW_DQBM: 530000},
    {WW_DQMC: '西藏自治区', WW_DQBM: 540000},
    
    {WW_DQMC: '陕西省', WW_DQBM: 610000},
    {WW_DQMC: '甘肃省', WW_DQBM: 620000},
    {WW_DQMC: '青海省', WW_DQBM: 630000},
    {WW_DQMC: '宁夏回族自治区', WW_DQBM: 640000},
    {WW_DQMC: '新疆维吾尔自治区', WW_DQBM: 650000},

    {WW_DQMC: '台湾省', WW_DQBM: 710000},
    
    {WW_DQMC: '香港特别行政区', WW_DQBM: 810000},
    {WW_DQMC: '澳门特别行政区', WW_DQBM: 820000}
  ]


  if(code){
    if(code == 110000){
      json = [
        {WW_DQMC: '东城区', WW_DQBM: 110101},
        {WW_DQMC: '西城区', WW_DQBM: 110102},
        {WW_DQMC: '朝阳区', WW_DQBM: 110105},
        {WW_DQMC: '丰台区', WW_DQBM: 110106},
        {WW_DQMC: '石景山', WW_DQBM: 110107},
        {WW_DQMC: '海淀区', WW_DQBM: 110108},
        {WW_DQMC: '门头沟', WW_DQBM: 110109},
        {WW_DQMC: '房山区', WW_DQBM: 110111},
        {WW_DQMC: '通州区', WW_DQBM: 110112},
        {WW_DQMC: '顺义区', WW_DQBM: 110113},
        {WW_DQMC: '昌平区', WW_DQBM: 110114},
        {WW_DQMC: '大兴区', WW_DQBM: 110115},
        {WW_DQMC: '怀柔区', WW_DQBM: 110116},
        {WW_DQMC: '平谷区', WW_DQBM: 110117},
        {WW_DQMC: '密云区', WW_DQBM: 110118},
        {WW_DQMC: '延庆区', WW_DQBM: 110119}
      ]
    } else if (code == 120000) {
      json = [
        {WW_DQMC: '和平区', WW_DQBM: 120101},
        {WW_DQMC: '河东区', WW_DQBM: 120102},
        {WW_DQMC: '河西区', WW_DQBM: 120103},
        {WW_DQMC: '南开区', WW_DQBM: 120104},
        {WW_DQMC: '河北区', WW_DQBM: 120105},
        {WW_DQMC: '红桥区', WW_DQBM: 120106},
        {WW_DQMC: '东丽区', WW_DQBM: 120110},
        {WW_DQMC: '西青区', WW_DQBM: 120111},
        {WW_DQMC: '津南区', WW_DQBM: 120112},
        {WW_DQMC: '北辰区', WW_DQBM: 120113},
        {WW_DQMC: '武清区', WW_DQBM: 120114},
        {WW_DQMC: '宝坻区', WW_DQBM: 120115},
        {WW_DQMC: '滨海新', WW_DQBM: 120116},
        {WW_DQMC: '宁河区', WW_DQBM: 120117},
        {WW_DQMC: '静海区', WW_DQBM: 120118},
        {WW_DQMC: '蓟州区', WW_DQBM: 120119}
      ]
    } else {
      json = []
    }
  }
  
  return builder(json)
}



Mock.mock(/\/xtsz\/template\/\d+/, 'get', getData)
Mock.mock(/\/xtsz\/template/, 'get', pageData)
Mock.mock(/\/xtsz\/dq/, 'get', dqData)